const cryptoJs = require("crypto-js")

function k(e) {
    i = {
        "devel": false,
        "host": "www.maomaozu.com"
    }
    var a = "55b3b62613aef1a029bd7231109e051d"
    return a = 0 == e ? a.substring(0, 16) : a.substring(16, 32)
}

function f(e, a) {
    return e = cryptoJs.enc.Utf8.parse(e),
        a = cryptoJs.enc.Utf8.parse(a),
        cryptoJs.AES.encrypt(a, e, {
            mode: cryptoJs.mode.CBC,
            padding: cryptoJs.pad.Pkcs7,
            iv: e
        }).toString()
}

function aes_encrypt(e) {
    return f(k(0), e)
}

/**
 * 输入页数获取解密请求体
 * @param page
 * @returns {*}
 */
function request_param(page) {
    a = {
        "Type": 0,
        "page": page,
        "expire": (new Date).getTime(),
    }
    return aes_encrypt(JSON.stringify(a))
}

function aes_decrypt(e) {
    var a = k(0).split("").reverse().join("");
    return d(a, e)
}

function d(e, a) {
    e = cryptoJs.enc.Utf8.parse(e);
    var l = cryptoJs.AES.decrypt(a, e, {
        mode: cryptoJs.mode.CBC,
        padding: cryptoJs.pad.Pkcs7,
        iv: e
    });
    return cryptoJs.enc.Utf8.stringify(l).toString()
}

/**
 * 解密返回数据
 * @param e
 * @returns {*}
 */
function response_data(e){
    e = e.replace(/^\s+|\s+$/gm, "")
    e = aes_decrypt(e)
    e = JSON.parse(e)
    return e
}
